package idv.csc.contact.dao.impl;

import idv.csc.contact.dao.ContactDAO;
import idv.csc.contact.po.ContactPO;

import java.util.List;


import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

@Repository
public class ContactDAOImpl implements ContactDAO {

	@Autowired
	private SessionFactory sessionFactory;

	public void addContact(ContactPO contact) {
		sessionFactory.getCurrentSession().save(contact);
	}
	
	@SuppressWarnings(value={"unchecked"})
	public List<ContactPO> listContact() {
		return sessionFactory.getCurrentSession().createQuery("from ContactPO")
				.list();
	}

	public void removeContact(Integer id) {
		ContactPO contact = (ContactPO) sessionFactory.getCurrentSession().load(
				ContactPO.class, id);
		if (null != contact) {
			sessionFactory.getCurrentSession().delete(contact);
		}

	}
}
